package DomainLayer;
import java.util.ArrayList;

public class Order
{
    private Customer customer;
    private Assistant assistant;
    private ArrayList<OrderLine> orderLines;
    private int id;
    private Invoice invoice;
    
    /**
     * @param id a ID of an order
     * @param customer the customer who bought goods.
     * @param assistant an empoloyee who is preceeding the order.
    */
    public Order(int id,Customer customer, Assistant assistant)
    {
        this.customer=customer;
        this.assistant=assistant;
        //Ordered materials list is added.
        orderLines= new ArrayList<OrderLine>();
        this.id=id;
        
    }

    public void addOrderLine(OrderLine orderLine)
    {
        orderLines.add(orderLine); 
        
    }
    
    public int getID()
    { 
        return id;
    }
    
    
    public double getTotalPrice()
    {
        double price=0;
        for (OrderLine orderLine: orderLines)
        {
            price+=orderLine.getOrderLinePrice();
        }
        return price;
    }
    
    //@return string of all ordered products in the order line.
    public String listOrderLine()
    {
        String s="        ###OrderLine###" + '\n';
        for(OrderLine orderLine: orderLines)
        {
             s+=orderLine.getQuantity() + " X " + orderLine.getProduct().getTitle() + 
            "    Price: " + orderLine.getOrderLinePrice() +    '\n';
        }
        return s;
        
    }
    
    public String getAssistantName()
    {
        return assistant.getName();
    }
        
    public String createInvoice()
    {
        invoice= new Invoice(getTotalPrice(), getAssistantName(), customer.getName(),
        customer.getAddress(),listOrderLine(),getID());
        return invoice.toString();
    }
}